﻿/*******************************************************
Copyright © 2008-2009 Active Technologies Group, Inc. (ATGi)

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*******************************************************/
using System.Collections.Generic;
using CommunityServer.Components;

namespace ATGi.CS.Components
{
    public interface ICentralizedFileStorageProvider
    {
        ICentralizedFile GetFile(string path, string fileName);
        IEnumerable<ICentralizedFile> GetFiles(string attachmentPath, PathSearchOption pathSearchOption);
        
        void AddUpdateFile(string attachmentPath, string previewFileName, System.IO.Stream previewStream);
        void Delete(string path, string fileName);

        // HACK: (JMB) The MakePath method really belongs on its own interface, since it is not a member of CentralizedFileStorageProvider.
        // However, the method needs to be abstracted in an interface, and so it is added here for convenience.
        string MakePath(int postID);
    }
    class CentralizedFileStorageProviderWrapper : ICentralizedFileStorageProvider 
    {
        public CentralizedFileStorageProvider BaseProvider { get; private set; }

        public CentralizedFileStorageProviderWrapper(string fileStoreKey)
        {
            BaseProvider = CentralizedFileStorageProvider.Instance(fileStoreKey);
        }

        public ICentralizedFile GetFile(string path, string fileName)
        {
            return BaseProvider.GetFile(path, fileName);
        }
        public IEnumerable<ICentralizedFile> GetFiles(string attachmentPath, PathSearchOption pathSearchOption)
        {
            return BaseProvider.GetFiles(attachmentPath, pathSearchOption);
        }
        
        public void AddUpdateFile(string attachmentPath, string previewFileName, System.IO.Stream previewStream)
        {
            BaseProvider.AddUpdateFile(attachmentPath, previewFileName, previewStream);
        }
        public void Delete(string path, string fileName)
        {
            BaseProvider.Delete(path, fileName);
        }

        public string MakePath(int postID)
        {
            return PostAttachments.MakePath(postID);
        }
    }
}
